package org.ossean.gather.model;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.InvalidPropertiesFormatException;
import java.util.List;
import java.util.Properties;

import org.apache.log4j.Logger;

public class Configure {

	private Properties prop = new Properties();
	Logger log4j = Logger.getLogger(Configure.class);
    private String pointerTableName;
    private List<String> sourceTableNameList = new ArrayList<String>();
    private String targetTableName;
    private String sourceFields;
    private String targetFields;
    private int idsIncrement;
    private int waitDataTime;
    private String andWhere;
    
    //自定义构造函数
    public Configure(String confPath) {
		confPath = confPath + ".xml";
		try {
			URL url = ClassLoader.getSystemResource(confPath);
			InputStream is = url.openStream();
			prop.loadFromXML(is);
		} catch (FileNotFoundException e) {
			log4j.error("Configure FileNotFoundException !");
			e.printStackTrace();
		} catch (InvalidPropertiesFormatException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		config();
	}
    
    private void config() {
        this.pointerTableName=prop.getProperty("pointerTableName");
		String sourceTableNameString = prop.getProperty("sourceTableName");
		String []sourceTableNameArray = sourceTableNameString.split(",");
		for(String sourceTableName : sourceTableNameArray){
			this.sourceTableNameList.add(sourceTableName);
		}
        this.sourceFields=prop.getProperty("sourceFields");
        this.targetTableName=prop.getProperty("targetTableName");
        this.targetFields=prop.getProperty("targetFields");
        this.idsIncrement=Integer.parseInt(prop.getProperty("idsIncrement"));
        this.waitDataTime=Integer.parseInt(prop.getProperty("waitDataTime"));
        this.andWhere=prop.getProperty("andWhere");
	}
    
	public Properties getProp() {
		return prop;
	}
	public void setProp(Properties prop) {
		this.prop = prop;
	}
	public Logger getLog4j() {
		return log4j;
	}
	public void setLog4j(Logger log4j) {
		this.log4j = log4j;
	}
	public String getPointerTableName() {
		return pointerTableName;
	}
	public void setPointerTableName(String pointerTableName) {
		this.pointerTableName = pointerTableName;
	}
	
	public List<String> getSourceTableNameList() {
		return sourceTableNameList;
	}

	public void setSourceTableNameList(List<String> sourceTableNameList) {
		this.sourceTableNameList = sourceTableNameList;
	}

	public String getTargetTableName() {
		return targetTableName;
	}
	public void setTargetTableName(String targetTableName) {
		this.targetTableName = targetTableName;
	}
	public String getSourceFields() {
		return sourceFields;
	}
	public void setSourceFields(String sourceFields) {
		this.sourceFields = sourceFields;
	}
	public String getTargetFields() {
		return targetFields;
	}
	public void setTargetFields(String targetFields) {
		this.targetFields = targetFields;
	}
	public int getIdsIncrement() {
		return idsIncrement;
	}
	public void setIdsIncrement(int idsIncrement) {
		this.idsIncrement = idsIncrement;
	}
	public int getWaitDataTime() {
		return waitDataTime;
	}
	public void setWaitDataTime(int waitDataTime) {
		this.waitDataTime = waitDataTime;
	}
	public String getAndWhere() {
		return andWhere;
	}
	public void setAndWhere(String andWhere) {
		this.andWhere = andWhere;
	}
    
    
}
